package com.sky.controller.admin;

import com.sky.result.Result;
import com.sky.utils.HWOssUtil;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.UUID;

/**
 * @Author: QingYingYan
 * @Date: 2025-10-20 18:39
 * @Description:
 */
@RestController
@Slf4j
@Api(tags = "图片上传")
@RequestMapping("/admin/common")
public class CommonController {
    @Autowired
    HWOssUtil hwOssUtil;
    @PostMapping("/upload")
    public Result upload(MultipartFile file) throws IOException {
        String originalFilename = file.getOriginalFilename();
        log.info("文件上传");
        String substring = originalFilename.substring(originalFilename.lastIndexOf("."));

        String s = UUID.randomUUID().toString() + substring;
        String url = hwOssUtil.upload(file.getBytes(), s);
        log.info("上传图片成功");
        return Result.success(url);

    }
}
